package org.jeecg.modules.demo.dajy.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.gson.JsonArray;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import org.apache.poi.hpsf.Thumbnail;
import org.jeecg.common.util.TreeBuilder;
import org.jeecg.modules.demo.api.controller.ApiInfoController;
import org.jeecg.modules.demo.dajy.entity.DaJyxx;
import org.jeecg.modules.demo.dajy.mapper.DaJyxxMapper;
import org.jeecg.modules.demo.api.mapper.ApiInfoMapper;
import net.coobird.thumbnailator.Thumbnails;
import org.jeecg.modules.demo.dajy.service.IDaJyxxService;
import org.jeecg.modules.demo.mlwj.mapper.DaMlwjMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;

/**
 * @Description: 复印调档表
 * @Author: jeecg-boot
 * @Date:   2023-11-27
 * @Version: V1.0
 */
@Service
public class DaJyxxServiceImpl extends ServiceImpl<DaJyxxMapper, DaJyxx> implements IDaJyxxService {
    @Autowired
    private DaJyxxMapper DjyMapper;
    @Autowired
    private ApiInfoMapper apiInfoMapper;
    @Value(value = "${jeecg.domainUrl.Dpuburl}")
    private String Dpuburl;
    @Value(value = "${jeecg.path.thumbnail}")
    private String thumbnail;
    @Value(value = "${jeecg.path.upload}")
    private String uploadpath;
    @Autowired
    private ApiInfoController apiInfoController;
    public JSONObject dauserlist(){
        JSONObject jsonObject = new JSONObject();
        try{
            jsonObject.put("code", 0);
            jsonObject.put("data", DjyMapper.getuserlist());

        }catch (Exception e){
            jsonObject.put("code", 1);
            jsonObject.put("msg", "");

        }
        return jsonObject;
    }
    public JSONObject addmlwj(String user, String orgcode, String jyr,String czlx ,  JSONArray filelist1,JSONArray filelist2,JSONArray filelist3,JSONArray filelist4,JSONArray filelist5,JSONArray filelist6,
                              JSONArray daarray,String bjyrxm,String bjyrid,String sqyy,String bjyrsfzh,String bjyrrwsj,String bjyrtwsj,String bjyrlxdh,String dwmc,String qmdata){
//        "uid" -> "vc-upload-1700727647742-36"
//        "lastModified" -> {Long@19418} 1596682923157
//        "lastModifiedDate" -> "2020-08-06T03:02:03.157Z"
//        "name" -> "1.jpg"
//        "size" -> {Integer@19424} 321257
//        "type" -> "image/jpeg"
//        "percent" -> {Integer@19428} 100
//        "originFileObj" -> {LinkedHashMap@19430}  size = 1
//        "status" -> "done"
//        "response" -> "http://192.168.2.7:8021/2023-11-23/17007295305111.jpg"
//        "xhr" -> {LinkedHashMap@19436}  size = 0
        JSONObject tmpRet = new JSONObject();
        try{
            String id = UUID.randomUUID().toString().replace("-", "");


            String qmnjurl = "";
            if (qmdata != null && !qmdata.equals("")) {
                String qmwjurl = apiInfoController.convertBase64ToImage(qmdata);
                String qmsourcePath = qmwjurl.replace(Dpuburl, uploadpath);
                String qmnewPath = qmwjurl.replace(Dpuburl, thumbnail);
                Thumbnails.of(qmsourcePath).scale(1f) //0-1 float 压缩大小
                        .outputQuality(0.7f) //0-1 压缩质量
                        .toFile(qmnewPath);
                qmnjurl = qmwjurl.replace(Dpuburl, Dpuburl + "thumbnail/");
                File qmfile = new File(qmwjurl);
                String qmwjmc = qmfile.getName();
                qmwjmc = qmwjmc.substring(0, qmwjmc.indexOf("."));
            }
            DjyMapper.jyrxxadd(user, orgcode, czlx,jyr,id,bjyrxm,bjyrid,sqyy,bjyrsfzh,bjyrrwsj,bjyrtwsj,bjyrlxdh,dwmc,qmnjurl,"data:image/png;base64,"+qmdata);
            String filename1 = "";
            String filename2 = "";
            String filename3 = "";
            String filename4 = "";
            String filename5 = "";
            String filename6 = "";

            if(czlx.equals("1")) {
                filename1 = "身份证";
                filename2 = "介绍信";
                filename3 = "退伍证";
                filename4 = "";
                filename5 = "";
                filename6 = "";
            }else{
                filename1 = "介绍信";
                filename2 = "调档函";
                filename3 = "工作人员工作证";
                filename4 = "工作人员身份证";
                filename5 = "退役士兵退伍证";
                filename6 = "退役士兵身份证";
            }
            for (int i = 0; i < filelist1.size(); i++) {
                String lx = filelist1.getJSONObject(i).getString("lx");
                if (lx.equals("upload")) {
                    JSONObject student = filelist1.getJSONObject(i);
                    String wjmc = student.getString("name");
                    wjmc = wjmc.substring(0, wjmc.indexOf("."));
                    String wjurl = student.getString("response");

                    String sourcePath = wjurl.replace(Dpuburl,uploadpath);
                    String newPath = wjurl.replace(Dpuburl,thumbnail);
                    Thumbnails.of(sourcePath).scale(1f) //0-1 float 压缩大小
                            .outputQuality(0.7f) //0-1 压缩质量
                            .toFile(newPath);
                    String njurl = wjurl.replace(Dpuburl,Dpuburl+"thumbnail/");

                    DjyMapper.jysqwjadd(user, orgcode, id, filename1,njurl,wjurl,filename1,newPath,sourcePath);
                }
                if (lx.equals("carmera")){
                    String baseStr = filelist1.getJSONObject(i).getString("value");
                    String wjurl = apiInfoController.base64File(baseStr);
                    String sourcePath = wjurl.replace(Dpuburl,uploadpath);
                    String newPath = wjurl.replace(Dpuburl,thumbnail);
                    Thumbnails.of(sourcePath).scale(1f) //0-1 float 压缩大小
                            .outputQuality(0.7f) //0-1 压缩质量
                            .toFile(newPath);
                    String njurl = wjurl.replace(Dpuburl,Dpuburl+"thumbnail/");
                    File file = new File(wjurl);
                    String wjmc = file.getName();
                    wjmc = wjmc.substring(0, wjmc.indexOf("."));
                    DjyMapper.jysqwjadd(user,orgcode,id,filename1,njurl,wjurl,filename1,newPath,sourcePath);
                }
            }
            for (int i = 0; i < filelist2.size(); i++) {
                String lx = filelist2.getJSONObject(i).getString("lx");
                if (lx.equals("upload")) {
                    JSONObject student = filelist2.getJSONObject(i);
                    String wjmc = student.getString("name");
                    wjmc = wjmc.substring(0, wjmc.indexOf("."));
                    String wjurl = student.getString("response");

                    String sourcePath = wjurl.replace(Dpuburl,uploadpath);
                    String newPath = wjurl.replace(Dpuburl,thumbnail);
                    Thumbnails.of(sourcePath).scale(1f) //0-1 float 压缩大小
                            .outputQuality(0.7f) //0-1 压缩质量
                            .toFile(newPath);
                    String njurl = wjurl.replace(Dpuburl,Dpuburl+"thumbnail/");

                    DjyMapper.jysqwjadd(user, orgcode, id, filename2,njurl,wjurl,filename2,newPath,sourcePath);
                }
                if (lx.equals("carmera")){
                    String baseStr = filelist2.getJSONObject(i).getString("value");
                    String wjurl = apiInfoController.base64File(baseStr);
                    String sourcePath = wjurl.replace(Dpuburl,uploadpath);
                    String newPath = wjurl.replace(Dpuburl,thumbnail);
                    Thumbnails.of(sourcePath).scale(1f) //0-1 float 压缩大小
                            .outputQuality(0.7f) //0-1 压缩质量
                            .toFile(newPath);
                    String njurl = wjurl.replace(Dpuburl,Dpuburl+"thumbnail/");
                    File file = new File(wjurl);
                    String wjmc = file.getName();
                    wjmc = wjmc.substring(0, wjmc.indexOf("."));
                    DjyMapper.jysqwjadd(user,orgcode,id,filename2,njurl,wjurl,filename2,newPath,sourcePath);
                }
            }
            for (int i = 0; i < filelist3.size(); i++) {
                String lx = filelist3.getJSONObject(i).getString("lx");
                if (lx.equals("upload")) {
                    JSONObject student = filelist3.getJSONObject(i);
                    String wjmc = student.getString("name");
                    wjmc = wjmc.substring(0, wjmc.indexOf("."));
                    String wjurl = student.getString("response");

                    String sourcePath = wjurl.replace(Dpuburl,uploadpath);
                    String newPath = wjurl.replace(Dpuburl,thumbnail);
                    Thumbnails.of(sourcePath).scale(1f) //0-1 float 压缩大小
                            .outputQuality(0.7f) //0-1 压缩质量
                            .toFile(newPath);
                    String njurl = wjurl.replace(Dpuburl,Dpuburl+"thumbnail/");

                    DjyMapper.jysqwjadd(user, orgcode, id, filename3,njurl,wjurl,filename3,newPath,sourcePath);
                }
                if (lx.equals("carmera")){
                    String baseStr = filelist3.getJSONObject(i).getString("value");
                    String wjurl = apiInfoController.base64File(baseStr);
                    String sourcePath = wjurl.replace(Dpuburl,uploadpath);
                    String newPath = wjurl.replace(Dpuburl,thumbnail);
                    Thumbnails.of(sourcePath).scale(1f) //0-1 float 压缩大小
                            .outputQuality(0.7f) //0-1 压缩质量
                            .toFile(newPath);
                    String njurl = wjurl.replace(Dpuburl,Dpuburl+"thumbnail/");
                    File file = new File(wjurl);
                    String wjmc = file.getName();
                    wjmc = wjmc.substring(0, wjmc.indexOf("."));
                    DjyMapper.jysqwjadd(user,orgcode,id,filename3,njurl,wjurl,filename3,newPath,sourcePath);
                }
            }
            if (czlx.equals("2")){
                for (int i = 0; i < filelist4.size(); i++) {
                    String lx = filelist4.getJSONObject(i).getString("lx");
                    if (lx.equals("upload")) {
                        JSONObject student = filelist4.getJSONObject(i);
                        String wjmc = student.getString("name");
                        wjmc = wjmc.substring(0, wjmc.indexOf("."));
                        String wjurl = student.getString("response");

                        String sourcePath = wjurl.replace(Dpuburl,uploadpath);
                        String newPath = wjurl.replace(Dpuburl,thumbnail);
                        Thumbnails.of(sourcePath).scale(1f) //0-1 float 压缩大小
                                .outputQuality(0.7f) //0-1 压缩质量
                                .toFile(newPath);
                        String njurl = wjurl.replace(Dpuburl,Dpuburl+"thumbnail/");

                        DjyMapper.jysqwjadd(user, orgcode, id, filename4,njurl,wjurl,filename4,newPath,sourcePath);
                    }
                    if (lx.equals("carmera")){
                        String baseStr = filelist4.getJSONObject(i).getString("value");
                        String wjurl = apiInfoController.base64File(baseStr);
                        String sourcePath = wjurl.replace(Dpuburl,uploadpath);
                        String newPath = wjurl.replace(Dpuburl,thumbnail);
                        Thumbnails.of(sourcePath).scale(1f) //0-1 float 压缩大小
                                .outputQuality(0.7f) //0-1 压缩质量
                                .toFile(newPath);
                        String njurl = wjurl.replace(Dpuburl,Dpuburl+"thumbnail/");
                        File file = new File(wjurl);
                        String wjmc = file.getName();
                        wjmc = wjmc.substring(0, wjmc.indexOf("."));
                        DjyMapper.jysqwjadd(user,orgcode,id,filename4,njurl,wjurl,filename4,newPath,sourcePath);
                    }
                }
                for (int i = 0; i < filelist5.size(); i++) {
                    String lx = filelist5.getJSONObject(i).getString("lx");
                    if (lx.equals("upload")) {
                        JSONObject student = filelist5.getJSONObject(i);
                        String wjmc = student.getString("name");
                        wjmc = wjmc.substring(0, wjmc.indexOf("."));
                        String wjurl = student.getString("response");

                        String sourcePath = wjurl.replace(Dpuburl,uploadpath);
                        String newPath = wjurl.replace(Dpuburl,thumbnail);
                        Thumbnails.of(sourcePath).scale(1f) //0-1 float 压缩大小
                                .outputQuality(0.7f) //0-1 压缩质量
                                .toFile(newPath);
                        String njurl = wjurl.replace(Dpuburl,Dpuburl+"thumbnail/");

                        DjyMapper.jysqwjadd(user, orgcode, id, filename5,njurl,wjurl,filename5,newPath,sourcePath);
                    }
                    if (lx.equals("carmera")){
                        String baseStr = filelist5.getJSONObject(i).getString("value");
                        String wjurl = apiInfoController.base64File(baseStr);
                        String sourcePath = wjurl.replace(Dpuburl,uploadpath);
                        String newPath = wjurl.replace(Dpuburl,thumbnail);
                        Thumbnails.of(sourcePath).scale(1f) //0-1 float 压缩大小
                                .outputQuality(0.7f) //0-1 压缩质量
                                .toFile(newPath);
                        String njurl = wjurl.replace(Dpuburl,Dpuburl+"thumbnail/");
                        File file = new File(wjurl);
                        String wjmc = file.getName();
                        wjmc = wjmc.substring(0, wjmc.indexOf("."));
                        DjyMapper.jysqwjadd(user,orgcode,id,filename5,njurl,wjurl,filename5,newPath,sourcePath);
                    }
                }
                for (int i = 0; i < filelist6.size(); i++) {
                    String lx = filelist6.getJSONObject(i).getString("lx");
                    if (lx.equals("upload")) {
                        JSONObject student = filelist6.getJSONObject(i);
                        String wjmc = student.getString("name");
                        wjmc = wjmc.substring(0, wjmc.indexOf("."));
                        String wjurl = student.getString("response");

                        String sourcePath = wjurl.replace(Dpuburl,uploadpath);
                        String newPath = wjurl.replace(Dpuburl,thumbnail);
                        Thumbnails.of(sourcePath).scale(1f) //0-1 float 压缩大小
                                .outputQuality(0.7f) //0-1 压缩质量
                                .toFile(newPath);
                        String njurl = wjurl.replace(Dpuburl,Dpuburl+"thumbnail/");

                        DjyMapper.jysqwjadd(user, orgcode, id, filename6,njurl,wjurl,filename6,newPath,sourcePath);
                    }
                    if (lx.equals("carmera")){
                        String baseStr = filelist6.getJSONObject(i).getString("value");
                        String wjurl = apiInfoController.base64File(baseStr);
                        String sourcePath = wjurl.replace(Dpuburl,uploadpath);
                        String newPath = wjurl.replace(Dpuburl,thumbnail);
                        Thumbnails.of(sourcePath).scale(1f) //0-1 float 压缩大小
                                .outputQuality(0.7f) //0-1 压缩质量
                                .toFile(newPath);
                        String njurl = wjurl.replace(Dpuburl,Dpuburl+"thumbnail/");
                        File file = new File(wjurl);
                        String wjmc = file.getName();
                        wjmc = wjmc.substring(0, wjmc.indexOf("."));
                        DjyMapper.jysqwjadd(user,orgcode,id,filename6,njurl,wjurl,filename6,newPath,sourcePath);
                    }
                }
            }
            for (int i = 0; i < daarray.size(); i++) {
//                "ryxm" -> "武乐"
//                "mlmc" -> "入伍材料1"
//                "ryid" -> "91285edd5632cd127d2fc787d22fb1b3"
//                "mlid" -> "1726517660298235905"
//                "id" -> "1acf68bb08bea46b5bcbf924c518e82e"
//                "wjdz" -> "http://192.168.2.7:8021/2023-11-23/17007315460195188.jpg"
//                "wjmc" -> "5188.jpg"

                JSONObject student = daarray.getJSONObject(i);
                String jyid = student.getString("id");
                String wjdz = student.getString("wjdz");
                String mlmc = student.getString("mlmc");
                String wjmc = student.getString("wjmc");
                DjyMapper.jywjadd(user,orgcode,id,jyid,wjdz, mlmc, wjmc);
            }
            tmpRet.put("code", "0");
        }
        catch(Exception ex){
            tmpRet.put("code", "1");
            tmpRet.put("msg", ex.toString());
        }
        return tmpRet;
    }

    public JSONObject getJyxx(String id){
        JSONObject tmpRet = new JSONObject();
        try{
            tmpRet.put("code", "0");
            tmpRet.put("data", DjyMapper.getjyxx(id) );

        }catch (Exception ex){
            tmpRet.put("code", "1");
            tmpRet.put("msg", ex.toString());
        }
        return tmpRet;
    }

    public JSONObject jymllist(String id){ //List<TreeBuilder.Node>
        JSONObject tmpRet = new JSONObject();
        List<TreeBuilder.Node> nodeList = new ArrayList<>();
        try{
            List<Map<String, Object>> temp = DjyMapper.getjyxx(id);
            String mid = "";
            String czlx = "";
            for(Map<String, Object> map : temp){
                mid = map.get("id").toString();
                czlx = map.get("czlx").toString();
                if (czlx == "1"){czlx = "复印档案";} else{ czlx = "调用材料";}
            }
            JsonArray answer = new JsonArray();
//            TreeBuilder.Node ml_node  = new TreeBuilder.Node(mid, "0", "借阅人信息","1", "信息", "", "", false,"0","","","","","","","");
//            TreeBuilder.Node ml_node1 = new TreeBuilder.Node("2", "0", "申请材料","2", "分类", "", "", false,"0","","","","","","","");
//            TreeBuilder.Node ml_node2 = new TreeBuilder.Node("3", "0", "申请"+czlx,"3", "分类", "", "", false,"0","","","","","","","");
//            nodeList.add(ml_node);
//            nodeList.add(ml_node1);
//            nodeList.add(ml_node2);
            List<Map<String, Object>> temp1 = DjyMapper.getjysqwj(id,"");
//            for (Map<String, Object> map : temp1){
//                String sqid = "";
//                String wjmc = "";
//                String wjdz = "";
//                String user = "";
//                String create_time = "";
//                if (map.get("id") != null){ sqid =  map.get("id").toString();}
//                if (map.get("wjmc") != null){ wjmc =  map.get("wjmc").toString();}
//                if (map.get("wjdz") != null){ wjdz =  map.get("wjdz").toString();}
//                if (map.get("realname") != null){ user =  map.get("realname").toString();}
//                if (map.get("create_time") != null){ create_time =  map.get("create_time").toString();}
//                TreeBuilder.Node node  = new TreeBuilder.Node(sqid, "2", wjmc,sqid, "文件", user, wjdz, false,"2",create_time,"","","","","","");
//                nodeList.add(node);
//            }
            List<Map<String, Object>> temp2 = DjyMapper.getjywj(id);
//            for (Map<String, Object> map : temp2){
//                String sqid = "";
//                String wjmc = "";
//                String wjdz = "";
//                String user = "";
//                String create_time = "";
//                String wjml = "";
//                if (map.get("id") != null){ sqid =  map.get("id").toString();}
//                if (map.get("wjmc") != null){ wjmc =  map.get("wjmc").toString();}
//                if (map.get("wjdz") != null){ wjdz =  map.get("wjdz").toString();}
//                if (map.get("realname") != null){ user =  map.get("realname").toString();}
//                if (map.get("create_time") != null){ create_time =  map.get("create_time").toString();}
//                if (map.get("wjml") != null){ wjml =  map.get("wjml").toString();}
//                TreeBuilder.Node node  = new TreeBuilder.Node(sqid, "3", wjmc,sqid, "文件", user, wjdz, false,"3",create_time,wjml,"","","","","");
//                nodeList.add(node);
//            }
            tmpRet.put("wjdata", temp2);
            tmpRet.put("sqdata", temp1);
            tmpRet.put("code", "0");
        }
        catch(Exception ex){
            tmpRet.put("code", "1");
            tmpRet.put("msg", ex.toString());
        }
        return tmpRet;
    }
    public String printPDF(String id,String shuser){
        Document document = new Document(PageSize.A4);
        File f=new File(uploadpath+"PDF");
        if (!f.exists())
            f.mkdirs();
        String wjname =  System.currentTimeMillis()+".pdf";
        String path =  f.getAbsolutePath()+"/"+wjname;
        try{
            List<Map<String, Object>> temp = DjyMapper.getjyxx(id);
            if (temp.size() == 1){
                String realname = "";
                String shyh="";
                String sqrq = "";
                String bjyrxm = "";
                String fsyh = "";
                String bjyrsfzh="";
                String bjyrrwsj="";
                String bjyrtwsj="";
                String bjyrlxdh="";
                String sqyy = "";


                String cyr_qmdata = "";
                String jbr_qmdata = "";
                String shr_qmdata = "";
                String czlx = temp.get(0).get("czlx").toString();



                if (temp.get(0).get("realname") != null){ realname =  temp.get(0).get("realname").toString();}
                if (temp.get(0).get("create_time") != null){
                    sqrq =  temp.get(0).get("create_time").toString();
                    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
                    Date date = formatter.parse(sqrq);
                    sqrq = formatter.format(date);

                }
                if (temp.get(0).get("bjyrxm") != null){ bjyrxm =  temp.get(0).get("bjyrxm").toString();}
                if (temp.get(0).get("shyh") != null){ shyh =  temp.get(0).get("shyh").toString();}
                if (temp.get(0).get("fsyh") != null){ fsyh =  temp.get(0).get("fsyh").toString();}
                if (temp.get(0).get("bjyrsfzh") != null){ bjyrsfzh =  temp.get(0).get("bjyrsfzh").toString();}
                if (temp.get(0).get("bjyrrwsj") != null){ bjyrrwsj =  temp.get(0).get("bjyrrwsj").toString();}
                if (temp.get(0).get("bjyrtwsj") != null){ bjyrtwsj =  temp.get(0).get("bjyrtwsj").toString();}
                if (temp.get(0).get("bjyrlxdh") != null){ bjyrlxdh =  temp.get(0).get("bjyrlxdh").toString();}
                if (temp.get(0).get("sqyy") != null){ sqyy =  temp.get(0).get("sqyy").toString();}
                if (temp.get(0).get("qmdata") != null){ cyr_qmdata =  temp.get(0).get("qmdata").toString();}
                if (temp.get(0).get("jbrqmdata") != null){ jbr_qmdata =  temp.get(0).get("jbrqmdata").toString();}
                if (temp.get(0).get("shyhqmdata") != null){ shr_qmdata =  temp.get(0).get("shyhqmdata").toString();}
                cyr_qmdata = cyr_qmdata.replace("data:image/png;base64,","");
                jbr_qmdata = jbr_qmdata.replace("data:image/png;base64,","");
                shr_qmdata = shr_qmdata.replace("data:image/png;base64,","");
                String bt = "";
                String ft = "";
//                if (czlx.equals("1")){
//                    bt = "申请复印档案目录";
//                    ft = "制单："+realname+"                 审核： "+shuser+"             申请人：\n\n";
//                }
//                if (czlx.equals("2")){
//                    bt = "申请调用档案目录";
//                    ft = "制单："+realname+"   初审： "+shyh+"      复审： "+shuser+"       申请人：\n\n";
//                }
                sqrq = sqrq.substring(0, 4)+"年"+sqrq.substring(5, 7)+"月"+sqrq.substring(8, 10)+"日";

                PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path));
                document.open();
                document.newPage();
                String fontPath=uploadpath+"SimHei.ttf";  //C:/WINDOWS/FONTS
                BaseFont bfChinese = BaseFont.createFont(fontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

                // 蓝色字体
                Font blueFont = new Font(bfChinese);
                blueFont.setColor(BaseColor.BLUE);
                blueFont.setSize(5);

                // 小三号
                Font smallThreeFont = new Font(bfChinese, 15);
                smallThreeFont.setColor(BaseColor.BLACK);

                // 五号
                Font fiveFont = new Font(bfChinese);
                fiveFont.setColor(BaseColor.BLACK);
                fiveFont.setSize(10.5f);

                // 五号
                Font smallFiveFont = new Font(bfChinese);
                smallFiveFont.setColor(BaseColor.BLACK);
                smallFiveFont.setSize(9);

                // 五号
                Font smallSixFont = new Font(bfChinese);
                smallSixFont.setColor(BaseColor.BLACK);
                smallSixFont.setSize(6.5f);

                // 小四号 加粗
                Font greenFont = new Font(bfChinese, 12, Font.BOLD);
                greenFont.setColor(BaseColor.BLACK);

                // 小四号
                Font messFont = new Font(bfChinese, 12);
                messFont.setColor(BaseColor.BLACK);


                // 标题加粗 四号
                Font titleFont = new Font(bfChinese, 14, Font.BOLD);
                titleFont.setColor(BaseColor.BLACK);


                // 设计一个4列的表.
                PdfPTable table = new PdfPTable(4);
                table.setWidthPercentage(100); // 宽度100%填充
                table.setSpacingBefore(10f); // 前间距
                table.setSpacingAfter(10f); // 后间距


                // 设置列宽
                float[] columnWidths = { 0.8f, 0.8f, 0.5f,0.5f};
                table.setWidths(columnWidths);
                PdfPCell cell;
//
//                //第一行
//                cell = new PdfPCell(new Phrase("", smallThreeFont));
//                cell.setMinimumHeight(20); // 设置单元格高度
//                cell.setUseAscender(true); // 设置可以居中
//                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
//                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
//                cell.setBorder(0);
//                table.addCell(cell);
//
//                cell = new PdfPCell(new Phrase(bt, smallThreeFont));
//                cell.setMinimumHeight(40); // 设置单元格高度
//                cell.setUseAscender(true); // 设置可以居中
//                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
//                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
//                cell.setBorderWidthTop(0);
//                cell.setBorderWidthLeft(0);
//                cell.setBorderWidthRight(0);
//                table.addCell(cell);
//
//                cell = new PdfPCell(new Phrase("", fiveFont));
//                cell.setMinimumHeight(2); // 设置单元格高度
//                cell.setUseAscender(true); // 设置可以居中
//                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
//                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
//                cell.setBorder(0);
//                table.addCell(cell);
//                //第二行
//
//                cell = new PdfPCell(new Phrase("", fiveFont));
//                cell.setMinimumHeight(40); // 设置单元格高度
//                cell.setUseAscender(true); // 设置可以居中
//                cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); // 设置水平居中
//                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
//                cell.setBorder(0);
//                table.addCell(cell);
//
//
//                //第三行
//
//                cell = new PdfPCell(new Phrase("", fiveFont));
//                cell.setMinimumHeight(40); // 设置单元格高度
//                cell.setUseAscender(true); // 设置可以居中
//                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
//                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
//                cell.setBorder(0);
//                table.addCell(cell);
//
//                cell = new PdfPCell(new Phrase("申请日期："+sqrq, fiveFont));
//                cell.setMinimumHeight(40); // 设置单元格高度
//                cell.setUseAscender(true); // 设置可以居中
//                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
//                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
//                cell.setBorder(0);
//                table.addCell(cell);
//
//                cell = new PdfPCell(new Phrase("档案人："+bjyrxm, fiveFont));
//                cell.setMinimumHeight(40); // 设置单元格高度
//                cell.setUseAscender(true); // 设置可以居中
//                cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); // 设置水平居中
//                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
//                cell.setBorder(0);
//                cell.setColspan(2);
//                table.addCell(cell);
//
//
//                PdfPTable pdfPTable = new PdfPTable(2);
//                pdfPTable.setWidthPercentage(100); // 宽度100%填充
//                cell = new PdfPCell(new Phrase("文件类型", fiveFont));
//                cell.setMinimumHeight(30); // 设置单元格高度
//                cell.setUseAscender(true); // 设置可以居中
//                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
//                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
//
//                pdfPTable.addCell(cell);
//                cell = new PdfPCell(new Phrase("文件名称", fiveFont));
//                cell.setMinimumHeight(30); // 设置单元格高度
//                cell.setUseAscender(true); // 设置可以居中
//                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
//                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
//                pdfPTable.addCell(cell);
//                /**
//                 * 加入到pdf文档中
//                 */
//                List<Map<String, Object>> lemp =  DjyMapper.getjywj(id);
//                for (Map<String, Object> map : lemp) {
//                    String wjml = "";
//                    String wjdz = "";
//                    String wjmc = "";
//                    if (map.get("wjdz") != null) { wjdz = map.get("wjdz").toString();}
//                    if (map.get("wjmc") != null) { wjmc = map.get("wjmc").toString();}
//                    if (map.get("wjml") != null) { wjml = map.get("wjml").toString();}
//
//                    cell = new PdfPCell(new Phrase(wjml, fiveFont));
//                    cell.setMinimumHeight(30); // 设置单元格高度
//                    cell.setUseAscender(true); // 设置可以居中
//                    cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
//                    cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
//
//                    pdfPTable.addCell(cell);
//                    cell = new PdfPCell(new Phrase(wjmc, fiveFont));
//                    cell.setMinimumHeight(30); // 设置单元格高度
//                    cell.setUseAscender(true); // 设置可以居中
//                    cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
//                    cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
//
//                    pdfPTable.addCell(cell);
//                }



                /**
                 * 加入到pdf文档中
                 */

//                cell = new PdfPCell(new Phrase("", fiveFont));
//                cell.setMinimumHeight(40); // 设置单元格高度
//                cell.setUseAscender(true); // 设置可以居中
//                cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); // 设置水平居中
//                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
//                cell.setBorder(0);
//                cell.setColspan(4);
//                cell.addElement(pdfPTable);
//                table.addCell(cell);
//                document.add(table);
//                // 表尾
//
//                Paragraph thrtionTitle = new Paragraph(ft, fiveFont);
//                thrtionTitle.setLeading(10);
//                thrtionTitle.setAlignment(Element.ALIGN_LEFT);
//                document.add(thrtionTitle);



                document.newPage();
                //查阅（复印）档案登记表
                // 设计一个4列的表.
                float[] columnWidths1 = { 0.8f};
                PdfPTable table1 = new PdfPTable(1);
                table1.setWidthPercentage(100); // 宽度100%填充
                table1.setSpacingBefore(10f); // 前间距
                table1.setSpacingAfter(10f); // 后间距

                bt = "查阅（复印）档案登记表";
                // 设置列宽
                table1.setWidths(columnWidths1);
                PdfPCell cell1;
                String qmstring = "D:\\software\\minio\\going-ctrl\\qm.png";
                //第一行
                cell1 = new PdfPCell(new Phrase("", smallThreeFont));
                cell1.setMinimumHeight(20); // 设置单元格高度
                cell1.setUseAscender(true); // 设置可以居中
                cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                cell1.setBorder(0);
                table1.addCell(cell1);

                cell1 = new PdfPCell(new Phrase(bt, smallThreeFont));
                cell1.setMinimumHeight(40); // 设置单元格高度
                cell1.setUseAscender(true); // 设置可以居中
                cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                cell1.setBorderWidthTop(0);
                cell1.setBorderWidthLeft(0);
                cell1.setBorderWidthRight(0);
                cell1.setBorderWidthBottom(0);
                table1.addCell(cell1);


                PdfPTable pdfPTable1 = new PdfPTable(6);
                pdfPTable1.setWidthPercentage(100); // 宽度100%填充

                for (int i = 0; i < 6; i++){
                    if (i == 0) {
                        cell1 = new PdfPCell(new Phrase("", fiveFont));
                        cell1.setMinimumHeight(30); // 设置单元格高度
                        cell1.setUseAscender(true); // 设置可以居中
                        cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                        cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中

                        pdfPTable1.addCell(cell1);
                        cell1 = new PdfPCell(new Phrase("姓名", fiveFont));
                        cell1.setMinimumHeight(30); // 设置单元格高度
                        cell1.setUseAscender(true); // 设置可以居中
                        cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                        cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                        pdfPTable1.addCell(cell1);
                        cell1 = new PdfPCell(new Phrase("身份证号", fiveFont));
                        cell1.setMinimumHeight(30); // 设置单元格高度
                        cell1.setUseAscender(true); // 设置可以居中
                        cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                        cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                        pdfPTable1.addCell(cell1);
                        cell1 = new PdfPCell(new Phrase("入伍时间", fiveFont));
                        cell1.setMinimumHeight(30); // 设置单元格高度
                        cell1.setUseAscender(true); // 设置可以居中
                        cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                        cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                        pdfPTable1.addCell(cell1);
                        cell1 = new PdfPCell(new Phrase("退伍时间", fiveFont));
                        cell1.setMinimumHeight(30); // 设置单元格高度
                        cell1.setUseAscender(true); // 设置可以居中
                        cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                        cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                        pdfPTable1.addCell(cell1);
                        cell1 = new PdfPCell(new Phrase("联系电话", fiveFont));
                        cell1.setMinimumHeight(30); // 设置单元格高度
                        cell1.setUseAscender(true); // 设置可以居中
                        cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                        cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                        pdfPTable1.addCell(cell1);
                    }
                    if (i == 1) {
                        cell1 = new PdfPCell(new Phrase("查档对象", fiveFont));
                        cell1.setMinimumHeight(30); // 设置单元格高度
                        cell1.setUseAscender(true); // 设置可以居中
                        cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                        cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中

                        pdfPTable1.addCell(cell1);
                        cell1 = new PdfPCell(new Phrase(bjyrxm, fiveFont));
                        cell1.setMinimumHeight(30); // 设置单元格高度
                        cell1.setUseAscender(true); // 设置可以居中
                        cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                        cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中

                        pdfPTable1.addCell(cell1);
                        cell1 = new PdfPCell(new Phrase(bjyrsfzh, fiveFont));
                        cell1.setMinimumHeight(30); // 设置单元格高度
                        cell1.setUseAscender(true); // 设置可以居中
                        cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                        cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                        pdfPTable1.addCell(cell1);
                        cell1 = new PdfPCell(new Phrase(bjyrrwsj, fiveFont));
                        cell1.setMinimumHeight(30); // 设置单元格高度
                        cell1.setUseAscender(true); // 设置可以居中
                        cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                        cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                        pdfPTable1.addCell(cell1);
                        cell1 = new PdfPCell(new Phrase(bjyrtwsj, fiveFont));
                        cell1.setMinimumHeight(30); // 设置单元格高度
                        cell1.setUseAscender(true); // 设置可以居中
                        cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                        cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                        pdfPTable1.addCell(cell1);
                        cell1 = new PdfPCell(new Phrase(bjyrlxdh, fiveFont));
                        cell1.setMinimumHeight(30); // 设置单元格高度
                        cell1.setUseAscender(true); // 设置可以居中
                        cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                        cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                        pdfPTable1.addCell(cell1);
                    }
                    if (i == 2) {
                        cell1 = new PdfPCell(new Phrase("查档事由及内容", fiveFont));
                        cell1.setMinimumHeight(60); // 设置单元格高度
                        cell1.setUseAscender(true); // 设置可以居中
                        cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                        cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                        pdfPTable1.addCell(cell1);

                        cell1 = new PdfPCell(new Phrase(sqyy, fiveFont));
                        cell1.setMinimumHeight(60); // 设置单元格高度
                        cell1.setUseAscender(true); // 设置可以居中
                        cell1.setColspan(5);
                        cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                        cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                        pdfPTable1.addCell(cell1);
                    }
                    if (i == 3) {
                        cell1 = new PdfPCell(new Phrase("查档事由及内容", fiveFont));
                        cell1.setMinimumHeight(300); // 设置单元格高度
                        cell1.setUseAscender(true); // 设置可以居中
                        cell1.setRowspan(6);
                        cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                        cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                        pdfPTable1.addCell(cell1);



                        cell1 = new PdfPCell(new Phrase("承诺事项\n"  , fiveFont));
                        cell1.setMinimumHeight(60); // 设置单元格高度
                        cell1.setUseAscender(true); // 设置可以居中
                        cell1.setColspan(5);
                        cell1.setBorderWidthTop(0);
                        cell1.setBorderWidthBottom(0);
                        cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                        cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中

                        pdfPTable1.addCell(cell1);
                        cell1 = new PdfPCell(new Phrase(
                                "1、本人（本单位）在绥化市退役军人事务局查阅和复印的档案资料，仅供本人（本单位）参考引用，未经允许绝不以任何形式公布，以及提供给他人、转让使用权。\n"  , fiveFont));
                        cell1.setMinimumHeight(40); // 设置单元格高度
                        cell1.setUseAscender(true); // 设置可以居中
                        cell1.setColspan(5);
                        cell1.setBorderWidthTop(0);
                        cell1.setBorderWidthBottom(0);
                        cell1.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); // 设置水平居中
                        cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中

                        pdfPTable1.addCell(cell1);
                        cell1 = new PdfPCell(new Phrase(
                                "2、不得擅自摘抄、拍摄、复印档案资料。如因工作需要复印档案资料，须经科室负责人核对签字，加盖公章生效。\n" , fiveFont));
                        cell1.setMinimumHeight(40); // 设置单元格高度
                        cell1.setUseAscender(true); // 设置可以居中
                        cell1.setColspan(5);
                        cell1.setBorderWidthTop(0);
                        cell1.setBorderWidthBottom(0);
                        cell1.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); // 设置水平居中
                        cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中

                        pdfPTable1.addCell(cell1);
                        cell1 = new PdfPCell(new Phrase(
                                "3、违反承诺条款，按照有关法律法规追究相应责任。\n"  , fiveFont));
                        cell1.setMinimumHeight(40); // 设置单元格高度
                        cell1.setUseAscender(true); // 设置可以居中
                        cell1.setColspan(5);
                        cell1.setBorderWidthTop(0);
                        cell1.setBorderWidthBottom(0);
                        cell1.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); // 设置水平居中
                        cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中

                        pdfPTable1.addCell(cell1);
                        cell1 = new PdfPCell(new Phrase(
                                "                                查档人签名：" , fiveFont));
                        cell1.setMinimumHeight(60); // 设置单元格高度
                        cell1.setUseAscender(true); // 设置可以居中
                        cell1.setColspan(4);
                        cell1.setBorderWidthTop(0);
                        cell1.setBorderWidthRight(0);
                        cell1.setBorderWidthBottom(0);
                        cell1.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); // 设置水平居中
                        cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中

                        pdfPTable1.addCell(cell1);

                        cell1 = new PdfPCell(new Phrase("管理员", fiveFont));
                        if (cyr_qmdata != null && !"".equals(cyr_qmdata)){
                            byte[] imageBytes = Base64.getDecoder().decode(cyr_qmdata);
                            // 创建字节数组输入流
                            ByteArrayInputStream bis = new ByteArrayInputStream(imageBytes);
                            // 通过ImageIO读取图像
                            BufferedImage image = ImageIO.read(bis);
                            bis.close();
                            Image logo = Image.getInstance(image, null);
                            float ywidth = logo.getScaledWidth();
                            float yheight = logo.getScaledHeight();
                            ywidth = ywidth * (40 / yheight);
                            logo.scaleAbsolute(ywidth, 40);// 调整图片大小(宽度 高度)
                            Phrase logoP = new Phrase("", fiveFont);
                            logoP.add(new Chunk(logo, 0, -5));
                            cell1.setPhrase(new Paragraph(new Chunk(logo, 0, 0)));
                        }
                        cell1.setMinimumHeight(60); // 设置单元格高度
                        cell1.setUseAscender(true); // 设置可以居中
                        cell1.setBorderWidthTop(0);
                        cell1.setBorderWidthLeft(0);
                        cell1.setBorderWidthBottom(0);
                        cell1.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); // 设置水平居中
                        cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                        pdfPTable1.addCell(cell1);

                        cell1 = new PdfPCell(new Phrase(
                                "                                查档日期：", fiveFont));
                        cell1.setMinimumHeight(30); // 设置单元格高度
                        cell1.setUseAscender(true); // 设置可以居中
                        cell1.setColspan(4);
                        cell1.setBorderWidthTop(0);
                        cell1.setBorderWidthRight(0);
                        cell1.setBorderWidthBottom(0);
                        cell1.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); // 设置水平居中
                        cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中

                        pdfPTable1.addCell(cell1);

                        cell1 = new PdfPCell(new Phrase( sqrq, fiveFont));
                        cell1.setMinimumHeight(30); // 设置单元格高度
                        cell1.setUseAscender(true); // 设置可以居中
                        cell1.setBorderWidthTop(0);
                        cell1.setBorderWidthLeft(0);
                        cell1.setBorderWidthBottom(0);
                        cell1.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); // 设置水平居中
                        cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中

                        pdfPTable1.addCell(cell1);
                    }
                    if (i == 4) {
                        cell1 = new PdfPCell(new Phrase("经办人签字", fiveFont));
                        cell1.setMinimumHeight(60); // 设置单元格高度
                        cell1.setUseAscender(true); // 设置可以居中
                        cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                        cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                        pdfPTable1.addCell(cell1);

                        cell1 = new PdfPCell(new Phrase("管理员", fiveFont));
                        if (jbr_qmdata != null && !"".equals(jbr_qmdata)){
                            byte[] imageBytes = Base64.getDecoder().decode(jbr_qmdata);
                            // 创建字节数组输入流
                            ByteArrayInputStream bis = new ByteArrayInputStream(imageBytes);
                            // 通过ImageIO读取图像
                            BufferedImage image = ImageIO.read(bis);
                            bis.close();
                            Image logo = Image.getInstance(image, null);
                            float ywidth = logo.getScaledWidth();
                            float yheight = logo.getScaledHeight();
                            ywidth = ywidth * (60 / yheight);
                            logo.scaleAbsolute(ywidth, 60);// 调整图片大小(宽度 高度)
                            Phrase logoP = new Phrase("", fiveFont);
                            logoP.add(new Chunk(logo, 0, -5));
                            cell1.setPhrase(new Paragraph(new Chunk(logo, 0, 0)));
                        }



                        cell1.setMinimumHeight(60); // 设置单元格高度
                        cell1.setUseAscender(true); // 设置可以居中
                        cell1.setColspan(5);
                        cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                        cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                        pdfPTable1.addCell(cell1);
                    }
                    if (i == 5) {
                        cell1 = new PdfPCell(new Phrase("安置科\n" +
                                "负责人签字", fiveFont));
                        cell1.setMinimumHeight(60); // 设置单元格高度
                        cell1.setUseAscender(true); // 设置可以居中
                        cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                        cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                        pdfPTable1.addCell(cell1);

                        cell1 = new PdfPCell(new Phrase("", fiveFont));
                        if (shr_qmdata != null && !"".equals(shr_qmdata)) {
                            byte[] imageBytes = Base64.getDecoder().decode(shr_qmdata);
                            // 创建字节数组输入流
                            ByteArrayInputStream bis = new ByteArrayInputStream(imageBytes);
                            // 通过ImageIO读取图像
                            BufferedImage image = ImageIO.read(bis);
                            bis.close();
                            Image logo = Image.getInstance(image, null);
                            float ywidth = logo.getScaledWidth();
                            float yheight = logo.getScaledHeight();
                            ywidth = ywidth * (60 / yheight);
                            logo.scaleAbsolute(ywidth, 60);// 调整图片大小(宽度 高度)
                            Phrase logoP = new Phrase("", fiveFont);
                            logoP.add(new Chunk(logo, 0, -5));
                            cell1.setPhrase(new Paragraph(new Chunk(logo, 0, 0)));
                        }
                        cell1.setMinimumHeight(60); // 设置单元格高度
                        cell1.setUseAscender(true); // 设置可以居中
                        cell1.setColspan(5);
                        cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                        cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                        pdfPTable1.addCell(cell1);
                    }
                }




                cell1 = new PdfPCell(new Phrase("", fiveFont));
                cell1.setMinimumHeight(40); // 设置单元格高度
                cell1.setUseAscender(true); // 设置可以居中
                cell1.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); // 设置水平居中
                cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                cell1.setBorder(0);
                cell1.setColspan(4);
                cell1.addElement(pdfPTable1);
                table1.addCell(cell1);
                document.add(table1);

//                for (Map<String, Object> map : lemp) {
//                    String wjdz = "";
//                    if (map.get("wjdz") != null) { wjdz = map.get("wjdz").toString();}
//                    wjdz = wjdz.replaceAll("/thumbnail", "");
//                    wjdz = wjdz.replaceAll(Dpuburl, uploadpath);
//                    document.setMargins(0, 0, -5, 0);//单位磅 1英寸=72磅
//                    document.newPage();
//                    Image image = Image.getInstance(wjdz);
//                    image.scaleAbsolute(PageSize.A4.getWidth()+5, PageSize.A4.getHeight());
//                    document.add(image);
//                }

                // 关闭文档
                document.close();
                // 关闭书写器
                writer.close();
            }

        }catch (Exception e){
           System.out.println(e.getMessage());
        }

        return Dpuburl+"PDF/"+wjname;
    }

    public String ddprintPDF(String jyid,String id,String shuser){
        Document document = new Document(PageSize.A4);
        File f=new File(uploadpath+"PDF");
        if (!f.exists())
            f.mkdirs();
        String wjname =  System.currentTimeMillis()+".pdf";
        String path =  f.getAbsolutePath()+"/"+wjname;
        try{
            List<Map<String, Object>> temp = DjyMapper.getjyxx(jyid);
            if (temp.size() == 1){
                String realname = "";
                String shyh="";
                String sqrq = "";
                String bjyrxm = "";
                String fsyh = "";
                String bjyrsfzh="";
                String bjyrrwsj="";
                String bjyrtwsj="";
                String bjyrlxdh="";
                String sqyy = "";
                String jyr = "";

                String cyr_qmdata = "";
                String jbr_qmdata = "";
                String shr_qmdata = "";
                String czlx = temp.get(0).get("czlx").toString();
                if (temp.get(0).get("realname") != null){ realname =  temp.get(0).get("realname").toString();}
                if (temp.get(0).get("create_time") != null){ sqrq =  temp.get(0).get("create_time").toString();}
                if (temp.get(0).get("bjyrxm") != null){ bjyrxm =  temp.get(0).get("bjyrxm").toString();}
                if (temp.get(0).get("shyh") != null){ shyh =  temp.get(0).get("shyh").toString();}
                if (temp.get(0).get("fsyh") != null){ fsyh =  temp.get(0).get("fsyh").toString();}
                if (temp.get(0).get("bjyrsfzh") != null){ bjyrsfzh =  temp.get(0).get("bjyrsfzh").toString();}
                if (temp.get(0).get("bjyrrwsj") != null){ bjyrrwsj =  temp.get(0).get("bjyrrwsj").toString();}
                if (temp.get(0).get("bjyrtwsj") != null){ bjyrtwsj =  temp.get(0).get("bjyrtwsj").toString();}
                if (temp.get(0).get("bjyrlxdh") != null){ bjyrlxdh =  temp.get(0).get("bjyrlxdh").toString();}
                if (temp.get(0).get("sqyy") != null){ sqyy =  temp.get(0).get("sqyy").toString();}
                if (temp.get(0).get("qmdata") != null){ cyr_qmdata =  temp.get(0).get("qmdata").toString();}
                if (temp.get(0).get("jbrqmdata") != null){ jbr_qmdata =  temp.get(0).get("jbrqmdata").toString();}
                if (temp.get(0).get("shyhqmdata") != null){ shr_qmdata =  temp.get(0).get("shyhqmdata").toString();}
                if (temp.get(0).get("jyr") != null){ jyr =  temp.get(0).get("jyr").toString();}
                cyr_qmdata = cyr_qmdata.replace("data:image/png;base64,","");
                jbr_qmdata = jbr_qmdata.replace("data:image/png;base64,","");
                shr_qmdata = shr_qmdata.replace("data:image/png;base64,","");
                String bt = "";
                String ft = "";
                bt = "档案目录";
                ft = "制单："+realname+"   初审： "+shyh+"      复审： "+shuser+"       接档人：        交档人：\n\n";
                sqrq = sqrq.substring(0, 4)+"年"+sqrq.substring(5, 7)+"月"+sqrq.substring(8, 10)+"日";

                PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path));
                document.open();
                document.newPage();
                String fontPath=uploadpath+"SimHei.ttf";  //C:/WINDOWS/FONTS
                BaseFont bfChinese = BaseFont.createFont(fontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

                // 蓝色字体
                Font blueFont = new Font(bfChinese);
                blueFont.setColor(BaseColor.BLUE);
                blueFont.setSize(5);

                // 小三号
                Font smallThreeFont = new Font(bfChinese, 15);
                smallThreeFont.setColor(BaseColor.BLACK);

                // 五号
                Font fiveFont = new Font(bfChinese);
                fiveFont.setColor(BaseColor.BLACK);
                fiveFont.setSize(10.5f);

                // 五号
                Font smallFiveFont = new Font(bfChinese);
                smallFiveFont.setColor(BaseColor.BLACK);
                smallFiveFont.setSize(9);

                // 五号
                Font smallSixFont = new Font(bfChinese);
                smallSixFont.setColor(BaseColor.BLACK);
                smallSixFont.setSize(6.5f);

                // 小四号 加粗
                Font greenFont = new Font(bfChinese, 12, Font.BOLD);
                greenFont.setColor(BaseColor.BLACK);

                // 小四号
                Font messFont = new Font(bfChinese, 12);
                messFont.setColor(BaseColor.BLACK);


                // 标题加粗 四号
                Font titleFont = new Font(bfChinese, 14, Font.BOLD);
                titleFont.setColor(BaseColor.BLACK);


                // 设计一个4列的表.
                PdfPTable table = new PdfPTable(4);
                table.setWidthPercentage(100); // 宽度100%填充
                table.setSpacingBefore(10f); // 前间距
                table.setSpacingAfter(10f); // 后间距


                // 设置列宽
                float[] columnWidths = { 0.8f, 0.8f, 0.5f,0.5f};
                table.setWidths(columnWidths);
                PdfPCell cell;

                //第一行
                cell = new PdfPCell(new Phrase("", smallThreeFont));
                cell.setMinimumHeight(20); // 设置单元格高度
                cell.setUseAscender(true); // 设置可以居中
                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                cell.setBorder(0);
                table.addCell(cell);

                cell = new PdfPCell(new Phrase(bt, smallThreeFont));
                cell.setMinimumHeight(40); // 设置单元格高度
                cell.setUseAscender(true); // 设置可以居中
                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                cell.setBorderWidthTop(0);
                cell.setBorderWidthLeft(0);
                cell.setBorderWidthRight(0);
                table.addCell(cell);

                cell = new PdfPCell(new Phrase("", fiveFont));
                cell.setMinimumHeight(2); // 设置单元格高度
                cell.setUseAscender(true); // 设置可以居中
                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                cell.setBorder(0);
                table.addCell(cell);
                //第二行

                cell = new PdfPCell(new Phrase("", fiveFont));
                cell.setMinimumHeight(40); // 设置单元格高度
                cell.setUseAscender(true); // 设置可以居中
                cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); // 设置水平居中
                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                cell.setBorder(0);
                table.addCell(cell);


                //第三行

                cell = new PdfPCell(new Phrase("", fiveFont));
                cell.setMinimumHeight(40); // 设置单元格高度
                cell.setUseAscender(true); // 设置可以居中
                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                cell.setBorder(0);
                table.addCell(cell);

                cell = new PdfPCell(new Phrase("调档日期："+sqrq, fiveFont));
                cell.setMinimumHeight(40); // 设置单元格高度
                cell.setUseAscender(true); // 设置可以居中
                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                cell.setBorder(0);
                table.addCell(cell);

                cell = new PdfPCell(new Phrase("档案人："+bjyrxm, fiveFont));
                cell.setMinimumHeight(40); // 设置单元格高度
                cell.setUseAscender(true); // 设置可以居中
                cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); // 设置水平居中
                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                cell.setBorder(0);
                cell.setColspan(2);
                table.addCell(cell);


                PdfPTable pdfPTable = new PdfPTable(3);
                pdfPTable.setWidthPercentage(100); // 宽度100%填充
                cell = new PdfPCell(new Phrase("序号", fiveFont));
                cell.setMinimumHeight(30); // 设置单元格高度
                cell.setUseAscender(true); // 设置可以居中
                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中

                pdfPTable.addCell(cell);
                pdfPTable.setWidthPercentage(100); // 宽度100%填充
                cell = new PdfPCell(new Phrase("文件类型", fiveFont));
                cell.setMinimumHeight(30); // 设置单元格高度
                cell.setUseAscender(true); // 设置可以居中
                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中

                pdfPTable.addCell(cell);
                cell = new PdfPCell(new Phrase("文件名称", fiveFont));
                cell.setMinimumHeight(30); // 设置单元格高度
                cell.setUseAscender(true); // 设置可以居中
                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                pdfPTable.addCell(cell);
                /**
                 * 加入到pdf文档中
                 */
                List<Map<String, Object>> lemp =  DjyMapper.getddwj(id);
                int i = 1;
                for (Map<String, Object> map : lemp) {
                    String wjml = "";
                    String wjdz = "";
                    String wjmc = "";
                    if (map.get("wjdz") != null) { wjdz = map.get("wjdz").toString();}
                    if (map.get("wjmc") != null) { wjmc = map.get("wjmc").toString();}
                    if (map.get("mlmc") != null) { wjml = map.get("mlmc").toString();}

                    cell = new PdfPCell(new Phrase(String.valueOf(i), fiveFont));
                    cell.setMinimumHeight(30); // 设置单元格高度
                    cell.setUseAscender(true); // 设置可以居中
                    cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                    cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中

                    pdfPTable.addCell(cell);
                    cell = new PdfPCell(new Phrase(wjml, fiveFont));
                    cell.setMinimumHeight(30); // 设置单元格高度
                    cell.setUseAscender(true); // 设置可以居中
                    cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                    cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中

                    pdfPTable.addCell(cell);
                    cell = new PdfPCell(new Phrase(wjmc, fiveFont));
                    cell.setMinimumHeight(30); // 设置单元格高度
                    cell.setUseAscender(true); // 设置可以居中
                    cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // 设置水平居中
                    cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中

                    pdfPTable.addCell(cell);
                    i = i + 1;
                }



                /**
                 * 加入到pdf文档中
                 */

                cell = new PdfPCell(new Phrase("", fiveFont));
                cell.setMinimumHeight(40); // 设置单元格高度
                cell.setUseAscender(true); // 设置可以居中
                cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); // 设置水平居中
                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); // 设置垂直居中
                cell.setBorder(0);
                cell.setColspan(4);
                cell.addElement(pdfPTable);
                table.addCell(cell);
                document.add(table);
                // 表尾

                Paragraph thrtionTitle = new Paragraph(ft, fiveFont);
                thrtionTitle.setLeading(10);
                thrtionTitle.setAlignment(Element.ALIGN_LEFT);
                document.add(thrtionTitle);
                // 关闭文档
                document.close();
                // 关闭书写器
                writer.close();
            }

        }catch (Exception e){
            System.out.println(e.getMessage());
        }

        return Dpuburl+"PDF/"+wjname;
    }
    public JSONObject jyshenhe(String user, String orgcode, String id,String zt,String realname,String bjyrid,String bhyy){
        JSONObject tmpRet = new JSONObject();
        try {
            String pdfurl="";
            DjyMapper.jyshenhe(user, orgcode, id,zt,pdfurl,bhyy);
            if (zt.equals("11") || zt.equals("31")){
                if (zt.equals("31")){
                    DjyMapper.jyupxx(bjyrid,"已调档");
                }
                if (zt.equals("11")){
                    pdfurl = printPDF(id,realname);
                }
                if (zt.equals("31")){
                    pdfurl = ddprintPDF(id,bjyrid,realname);
                }
            }
            DjyMapper.jyshenhe(user, orgcode, id,zt,pdfurl,bhyy);

            tmpRet.put("code", "0");
        }
        catch(Exception ex){
            tmpRet.put("code", "1");
            tmpRet.put("msg", ex.toString());
        }
        return tmpRet;
    }
    public Page<DaJyxx> getxxByUser(Page<DaJyxx>page , String user,String userid,String jyr,String czlx){
        //            --   1730137636376555521
//            -- 调用复审  1730137865066786818
//            -- 调用初审  1730137769117888514
//        Integer fy = apiInfoMapper.getuserFeature(userid,"1730137636376555521"); //复印审核
//        Integer dy2 = apiInfoMapper.getuserFeature(userid,"1730137865066786818"); //调用复审
//        Integer dy1 = apiInfoMapper.getuserFeature(userid,"1730137769117888514"); //调用初审
//        Integer czlx = 3;
//        if (fy > 0)
//        {
//            if (dy1 > 0 || dy2 > 0){
//                czlx = 0;
//            }
//            else{
//                czlx = 1;
//            }
//        }else{
//            if (dy1 > 0 || dy2 > 0){
//                czlx = 2;
//            }
//            else{
//                czlx = 3;
//            }
//        }

        return  page.setRecords(DjyMapper.getxxByUser(page,user,Integer.parseInt(czlx),jyr));
    }
    public Page<DaJyxx> getlist(Page<DaJyxx>page , String jyr,String czlx){
        return page.setRecords(this.DjyMapper.getlist(page,jyr,czlx));
    }
    public JSONObject addhcwj(String user,String orgcode,String id , JSONArray wjarray,String lx){
        JSONObject tmpRet = new JSONObject();
        try{
            for (int i = 0; i < wjarray.size(); i++) {
                if (lx.equals("upload")){
                    JSONObject student = wjarray.getJSONObject(i);
                    String wjmc = student.getString("name");

                    wjmc = wjmc.substring(0, wjmc.indexOf("."));
                    String wjurl = student.getString("response");
                    String sourcePath = wjurl.replace(Dpuburl,uploadpath);
                    String newPath = wjurl.replace(Dpuburl,thumbnail);
                    Thumbnails.of(sourcePath).scale(1f) //0-1 float 压缩大小
                            .outputQuality(0.7f) //0-1 压缩质量
                            .toFile(newPath);
                    String njurl = wjurl.replace(Dpuburl,Dpuburl+"thumbnail/");

                    File file = new File(sourcePath);
                    long fileSize = file.length();
                    DjyMapper.hcwjadd(user, orgcode, id, wjmc,njurl,wjurl, newPath,sourcePath,"回传");
                }
                if (lx.equals("carmera")){
                    String baseStr = wjarray.getString(i);
                    String wjurl = apiInfoController.base64File(baseStr);
                    String sourcePath = wjurl.replace(Dpuburl,uploadpath);
                    String newPath = wjurl.replace(Dpuburl,thumbnail);
                    Thumbnails.of(sourcePath).scale(1f) //0-1 float 压缩大小
                            .outputQuality(0.7f) //0-1 压缩质量
                            .toFile(newPath);
                    String njurl = wjurl.replace(Dpuburl,Dpuburl+"thumbnail/");
                    File file = new File(wjurl);
                    String wjmc = file.getName();
                    wjmc = wjmc.substring(0, wjmc.indexOf("."));
                    File sile = new File(sourcePath);
                    long fileSize = sile.length();
                    DjyMapper.hcwjadd(user, orgcode, id, wjmc,njurl,wjurl, newPath,sourcePath,"回传");
                }
            }
            DjyMapper.jyxxhc(id);
            tmpRet.put("code", "0");
        }
        catch(Exception ex){
            tmpRet.put("code", "1");
            tmpRet.put("msg", ex.toString());
        }
        return tmpRet;
    }
    public JSONObject gethcwjlist(String id){
        JSONObject tmpRet = new JSONObject();
        try
        {
            tmpRet.put("data", DjyMapper.gethcwj(id));
            tmpRet.put("code", "0");

        }catch (Exception ex){
            tmpRet.put("code", "1");
            tmpRet.put("msg", ex.toString());
        }
        return tmpRet;
    }
}

